

import java.awt.List;
import java.util.LinkedList;

import engine.Edge;
import engine.Force;
import engine.PhysicsObject;
import engine.Vector;
import engine.Vertex;

import quadTree.BoundingBox;

import junit.framework.*;

public class PhysicsObjectTest extends TestCase {

	public void testConstructPhysicsObject()
	{
		LinkedList<Vertex> vertList = new LinkedList<Vertex>();
		LinkedList<Edge> edges = new LinkedList<Edge>();
		Vertex vert1 = new Vertex(new Vector(1,1));
		Vertex vert2 = new Vertex(new Vector(2,1));
		Vertex vert3 = new Vertex(new Vector(2,2));
		Vertex vert4 = new Vertex(new Vector(1,2));
		
		vertList.add(vert1);
		vertList.add(vert2);
		vertList.add(vert3);
		vertList.add(vert4);//stationary square
		
		Edge e1 = new Edge(vert1,vert2,20);
		Edge e2 = new Edge(vert2,vert3,20);
		Edge e3 = new Edge(vert3,vert4,20);
		Edge e4 = new Edge(vert4,vert1,20);
		edges.add(e1);
		vert1.addEdge(e1);
		vert2.addEdge(e1);
		edges.add(e2);
		vert2.addEdge(e2);
		vert3.addEdge(e2);
		edges.add(e3);
		vert3.addEdge(e3);
		vert4.addEdge(e3);
		edges.add(e4);
		vert4.addEdge(e4);
		vert1.addEdge(e4);
		
		float mass = 20;
		int index = 0;
		Vector velocity = new Vector(0,0);
		PhysicsObject test = new PhysicsObject(index, vertList, mass, edges, velocity);
		assertTrue(test.getVertexList().equals(vertList));
		assertTrue(test.getMass()==mass);
		assertTrue(test.getIndex()==index);
		
		BoundingBox testBox = test.getBoundingBox();
		assertTrue(testBox!=null);
		
		Vector center = test.getCenterOfMass();
		assertTrue(center!=null);
		
		test.setMass(40);
		assertTrue(test.getMass()==40);
		
		Vector v1 = new Vector(2,2);
		test.setVelocity(v1);
		assertTrue(test.getVelocity().equals(v1));
		
		test.setEdges(edges);
		assertTrue(test.getEdges().equals(edges));
		
		LinkedList<Edge> e = (LinkedList<Edge>) test.getEdges();
		assertTrue(e.equals(test.getEdges()));
		
		float m = test.getMass();
		assertTrue(test.getMass()==m);
		
		Vector vel = test.getVelocity();
		assertTrue(vel.equals(test.getVelocity()));
		
		LinkedList<Vertex> v = (LinkedList<Vertex>) test.getVertexList();
		assertTrue(v.equals(vertList));

		
		test.setVelocity(new Vector(0,0));
		test.update(1, 0);
		assertTrue(test.getPosition().getX()==1.5);
		assertTrue(test.getPosition().getY()==1.5);
		

		test.setVelocity(new Vector(1,0));
		test.update(1, 0);
		assertTrue(test.getPosition().getX()==2.5);
		assertTrue(test.getPosition().getY()==1.5);
		
		test.setVelocity(new Vector(1,1));
		test.update(1, 0);
		assertTrue(test.getPosition().getX()==3.5);
		assertTrue(test.getPosition().getY()==2.5);
		
		test.setVelocity(new Vector(0,0));
		
		PhysicsObject test2 = new PhysicsObject(index, vertList, mass, edges, velocity);
		assertTrue(test.isColliding(test2)==null);
		
		Force f = new Force(new Vector((float)3.5,(float)2.5), new Vector(5,0), 12);
		
		test.applyForce(f, 1);//starting from 3.25, mass 40.  a = 5.  f= m/a, a = m/f
		assertTrue(test.getPosition().getX()==3.5625);//a = .125, p = (3.5,2.5), initial vel = 0,0 time = 1
		
		test.setAngle(5);
		assertTrue(test.getAngle()==5);
		
		test.setInertiaTensor(5);
		assertTrue(test.getInertiaTensor()==5);
		
		test.setAngularVelo(5);
		assertTrue(test.getAngularVelo()==5);
		
	}
	
	public static void main(String args[])
	{
		PhysicsObjectTest poTest = new PhysicsObjectTest();
		poTest.testConstructPhysicsObject();
		
		
	}
}
